<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>系统配置</title>
    <link rel="stylesheet" th:href="@{/layui/layui/css/layui.css}">
</head>
<body>
<div class="layui-main">
    <br />
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="111">首页设置</li>
            <li lay-id="222">百度统计</li>
            <li lay-id="333">上传配置</li>
            <li lay-id="444">站点配置</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">首页公告</label>
                        <div class="layui-input-block">
                            <input id="notice" type="text" name="title" autocomplete="off" placeholder="首页公告" class="layui-input"
                                   th:value="${config.getNotice()}"/>
                            <span style="color: #DAA5A6;">欲想显示多个公告请用 | 分开</span>
                        </div>
                    </div>
                    <br/>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站标题</label>
                    <div class="layui-input-block">
                        <input id="webname" type="text" name="title" autocomplete="off" placeholder="网站标题" class="layui-input"
                               th:value="${config.getWebname()}"/>
                    </div>
                </div>
                <br />
                    <div class="layui-form-item">
                        <label class="layui-form-label">站点域名</label>
                        <div class="layui-input-block">
                            <input id="domain" type="text" name="title" autocomplete="off" placeholder="站点域名" class="layui-input"
                                   th:value="${config.getDomain()}"/><span style="color: #DAA5A6;">填写访问本站的域名或IP,需带有http://或https://,否则开启邮箱激活和本地存储不能正常使用。如：http://127.0.0.1:8088,IP需带端口,最后不需要加/</span>
                        </div>
                    </div>
                    <br />
                <div class="layui-form-item">
                    <label class="layui-form-label">站点说明</label>
                    <div class="layui-input-block">
                        <input id="explain" type="text" name="title" autocomplete="off" class="layui-input"
                               th:value="${config.getExplain()}"/>
                    </div>
                </div>
<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label">底部版权</label>-->
<!--                    <div class="layui-input-block">-->
<!--                        <input id="footed" type="text" name="title" autocomplete="off" placeholder="底部版权" class="layui-input"-->
<!--                               th:value="${config.getFooted()}"/>-->
<!--                    </div>-->
<!--                </div>-->

                    <br />
                        <div class="layui-form-item">
                            <label class="layui-form-label">视频背景</label>
                            <div class="layui-input-block">
                                <input id="video" type="text" name="title" autocomplete="off" placeholder="视频url地址" class="layui-input"
                                       th:value="${config.getVideo()}"/><span style="color: #DAA5A6;">如果你的服务器带宽较差，不建议使用视频背景</span>
                            </div>
                        </div>
                    <br />
                    <div class="layui-form-item">
                        <label class="layui-form-label">首页背景一</label>
                        <div class="layui-input-block">
                            <input id="background1" type="text" name="title" autocomplete="off" placeholder="首页背景图" class="layui-input"
                                   th:value="${config.getBackground1()}"/>
                        </div>
                    </div>
                    <br />
                    <div class="layui-form-item">
                        <label class="layui-form-label">首页背景二</label>
                        <div class="layui-input-block">
                            <input id="background2" type="text" name="title" autocomplete="off" placeholder="上传页面背景图" class="layui-input"
                                   th:value="${config.getBackground2()}"/>
                        </div>
                    </div>
                    <br />
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">每日随机图</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input id="open" type="checkbox" name="close" lay-skin="switch" lay-filter="switchTest"-->
<!--                                   lay-text="ON|OFF">-->
<!--                            <span style="color: #DAA5A6;">　采集必应每日壁纸，开启随机背景后，手动设置的首页背景将会失效</span>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <br />-->

                <div class="layui-form-item">
                    <label class="layui-form-label">备案显示</label>
                    <div class="layui-input-block">
                        <textarea id="links" name="links" placeholder="备案号，可用html代码" class="layui-textarea" th:text="${config.getLinks()}"></textarea>
                        <span style="color: #DAA5A6;">不填写，则不显示<xmp></xmp></span>
                    </div>
                </div>

                    <br />
                    <form class="layui-form-item " >
                        <div class="laydfdaui-form-item">
                            <label class="layui-form-label">背景类型</label>
                            <div class="layui-input-block" id="backtype">
                                <input type="radio" id="backtype1" name="isbacktype" value="1" title="图片壁纸">
                                <input type="radio" id="backtype2" name="isbacktype" value="2" title="视频壁纸">
                            </div>
                        </div>
                        <br />
                        <div class="laydfdaui-form-item">
                            <label class="layui-form-label">首页类型</label>
                            <div class="layui-input-block" id="sett">
                                <input type="radio" id="sett11" name="settweb" value="1" title="默认首页">
                                <input type="radio" id="sett22" name="settweb" value="2" title="精简首页">
                            </div><span style="color: #DAA5A6;">精简首页：页面加载完直接打开上传页面，没有展示页</span>
                        </div>
                    </form>
                    </form>
                </form>
                <a class="layui-btn" lay-filter="demo2" style="float: right;margin-right: 50px;" onclick="updateconfig()">保存</a>
            </div>
            <div class="layui-tab-item">
                <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">统计JS代码</label>
                    <div class="layui-input-block">
                        <textarea id="baidu" name="baidu" placeholder="请输入统计JS代码" class="layui-textarea" th:text="${config.getBaidu()}"></textarea>
                        <span style="color: #DAA5A6;"><xmp>添加网站统计的JS代码，不需要要添加<script>标签</script></xmp></span>
                    </div>
                    <a class="layui-btn" lay-filter="demo2" style="float: right;margin-right: 50px;" onclick="updatebaidu()">保存</a>
                </div>
                </form>
            </div>
<!--分组3-->


            <div class="layui-tab-item">
                <h3 style="margin-top: 50px;">站点API配置</h3>
                <hr />
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">图床API</label>
                        <div class="layui-input-block">
                            <input id="bedapi" type="checkbox" name="close" lay-skin="switch" lay-filter="switchTest2"
                                   lay-text="开启|关闭">
                        </div>
                    </div>
                </form>
                <br />
                <h3>游客上传配置</h3>
                <hr />
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">游客上传</label>
                        <div class="layui-input-block">
                            <input id="upopen" type="checkbox" name="close" lay-skin="switch" lay-filter="switchTest"
                                   lay-text="开启|关闭">
                        </div>
                    </div>
                </form>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 100px;">单文件大小(M)</label>
                    <div class="layui-input-inline" style="width: 100px;">
                        <input id="filesizetourists" th:value="${updateConfig.getFilesizetourists()}"  type="text" name="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: 50px;">
                    <label class="layui-form-label" style="width: 100px;">单次上传个数</label>
                    <div class="layui-input-inline" style="width: 100px;">
                        <input id="imgcounttourists" th:value="${updateConfig.getImgcounttourists()}" type="text" name="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <br />
                <h3 style="margin-top: 50px;">会员上传配置</h3>
                <hr />
                <div class="layui-inline" >
                    <label class="layui-form-label" style="width: 100px;">单文件大小(M)</label>
                    <div class="layui-input-inline" style="width: 100px;">
                        <input id="filesizeuser" th:value="${updateConfig.getFilesizeuser()}" type="text" name="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: 50px;">
                    <label class="layui-form-label" style="width: 100px;">单次上传个数</label>
                    <div class="layui-input-inline" style="width: 100px;">
                        <input id="imgcountuser" th:value="${updateConfig.getImgcountuser()}" type="text" name="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <br />
                <h3 style="margin-top: 50px;">存储容量分配(M)&nbsp;&nbsp;<span style="color: #DAA5A6;">输入“-1”则为无限制</span></h3>
                <hr />
                <div class="layui-inline" >
                    <label class="layui-form-label" style="width: 100px;">游客可用总容量</label>
                    <div class="layui-input-inline" style="width: 100px;">
                        <input id="visitormemory" th:value="${updateConfig.getVisitormemory()}" lay-verify="required" type="text" name="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: 50px;">
                    <label class="layui-form-label" style="width: 100px;">用户初始容量</label>
                    <div class="layui-input-inline" style="width: 100px;">
                        <input id="usermemory" th:value="${updateConfig.getUsermemory()}" lay-verify="required" type="text" name="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <br />
                <h3 style="margin-top: 50px;">支持文件配置</h3>
                <hr />
                <div class="layui-form-item">
                    <label class="layui-form-label">文件类型</label>
                    <div class="layui-input-block">
                        <input id="suffix" th:value="${updateConfig.getSuffix()}" type="text" name="title" required  lay-verify="required" placeholder="配置可上传的文件类型" autocomplete="off" class="layui-input">
                        <span style="color: #DAA5A6;">配个类型用“ , ”隔开</span>
                    </div>
                </div>
                <h3 style="margin-top: 50px;">图片链接格式</h3>
                <hr />
                <form class="layui-form " >
                <div class="laydfdaui-form-item">
                    <label class="layui-form-label">链接格式</label>
                    <div class="layui-input-block" id="imgurltype">
                        <input type="radio" id="urltype1" name="urltype" value="1" title="用户名格式：/user/">
                        <input type="radio" id="urltype2" name="urltype" value="2" title="日期格式：/YY/mm/dd/" checked>
                    </div>
                </div>
                </form>
                <br />

                <a class="layui-btn" lay-filter="demo2" style="float: right;margin-right: 50px;" onclick="scconfig()">保存</a>
            </div>
            <!--站点设置-->
            <div class="layui-tab-item">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">开放注册</label>
                        <div class="layui-input-block">
                            <input id="dologo" type="checkbox" name="close" lay-skin="switch" lay-filter="switchTest3"
                                   lay-text="开启|关闭">
                        </div>
                    </div>
                </form>
<!--                <form class="layui-form">-->
<!--                    <label class="layui-form-label">默认群组</label>-->
<!--                    <div class="layui-input-inline" style="width: 250px;">-->
<!--                        <select id="group"  name="quiz1" style="max-height: 360px;" lay-filter="group">-->

<!--                        </select>-->
<!--                    </div>-->
<!--                </form>-->
                <h3>更多功能陆续开放...</h3>
                <br />

<!--                <a class="layui-btn" lay-filter="demo2" style="float: right;margin-right: 50px;" onclick="webset()">保存</a>-->
            </div>
        </div>
    </div>
</div>
<script th:src="@{/static/js/jquery-3.4.1.min.js}" type="text/javascript"></script>
<script th:src="@{/layui/layui/layui.js}"></script>

    <script type="text/javascript">
        var isupval = [[${updateConfig.getIsupdate()}]];
        var isapi = [[${updateConfig.getApi()}]];
        var state = [[${sysconfig==null?0:sysconfig.getRegister()}]];
        var group = [[${group}]];
        $(function () {
            layui.use(['form','table','element'], function(){
                var table = layui.table;
                var element = layui.element;
                var form = layui.form;
                //监听指定开关
                form.on('switch(switchTest)', function (data) {
                    if (this.checked == true) {
                        isupdate(1);
                    } else {
                        isupdate(0);
                    }
                });
                form.on('switch(switchTest2)', function (data) {
                    if (this.checked == true) {
                        upapi(1);
                    } else {
                        upapi(0);
                    }
                });
                form.on('switch(switchTest3)', function (data) {
                    if (this.checked == true) {
                        setstate(1);
                    } else {
                        setstate(2);
                    }
                });
                form.on('select(group)', function(data){
                    group = data.value;
                });
                $('#group').val(group);
                form.render('select');
                });
            if (isupval == 1) {
                $('#upopen').attr("checked", 'hellohao'); //增加属性
            } else {
                $('#upopen').removeAttr("checked"); //移除属性
            }
            if (isapi == 1) {
                $('#bedapi').attr("checked", 'hellohao'); //增加属性
            } else {
                $('#bedapi').removeAttr("checked"); //移除属性
            }
            if (state == 1) {
                $('#dologo').attr("checked", 'hellohao'); //增加属性
            } else {
                $('#dologo').removeAttr("checked"); //移除属性
            }
        });
        $(function () {
           var usertype = [[${updateConfig.getUrltype()!=null?updateConfig.getUrltype():1}]];
            var backtype = [[${config.getBacktype()!=null?config.getBacktype():1}]];
            var sett = [[${config.getSett()}]];
            if(usertype==2){
               $('#urltype2:radio:input:radio:last').attr('checked', 'true');
           }else{
               $('#urltype1:radio:first').attr('checked', 'true');
           }
           if(backtype==2){
               $('#backtype2:radio:input:radio:last').attr('checked', 'true');
           }else{
               $('#backtype1:radio:first').attr('checked', 'true');
           }

            if(sett != 1){
                $('#sett22:radio:input:radio:last').attr('checked', 'true');
            }else{
                $('#sett11:radio:first').attr('checked', 'true');
            }

            $.ajax({
                type: "POST",
                url: "/admin/root/getgrouplist",
                //data: {groupid:groupid},
                dataType: "json",
                success: function (data) {
                    var body = '';//<option value="0">&nbsp;默认群组</option>
                    for(var i=0;i<data.length;i++){
                        body+='<option value="'+data[i].id+'">'+data[i].groupname+'</option>';
                    }
                    $('#group').append(body);
                    form.render('select');
                }
            });


        });
        function updateconfig() {
                var webname = $("#webname").val();
                var explain = $("#explain").val();
                var video = $("#video").val();
                var backtype = $('#backtype input[name="isbacktype"]:checked ').val();
                var links = $("#links").val();
                var notice = $("#notice").val();
                var domain = $("#domain").val();
                var background1 = $("#background1").val();
                var background2 = $("#background2").val();
                var sett = $('#sett input[name="settweb"]:checked ').val();
                if (webname != "" && domain!="" ) {
                    $.ajax({
                        type: "POST",
                        url: "/admin/root/updateconfig",
                        dataType: "json",
                        data: {webname: webname, explain: explain, video: video,backtype:backtype,links:links,notice:notice,domain:domain,background1:background1,background2:background2,sett:sett},
                        success: function (data) {
                            var vals = Number(data);
                            if (vals > 0) {
                                layer.msg("保存成功", {icon: 1});
                                //window.location.reload();
                            } else {
                                layer.msg("保存失败，请尝试刷新页面后操作", {icon: 2});
                            }
                        }
                    });
                } else {
                    layer.msg("网站名称或站点域名均不能为空", {icon: 2});
                }
        }
        function updatebaidu() {
            var baidu = $("#baidu").val();
            $.ajax({
                type: "POST",
                url: "/admin/root/updateconfig",
                dataType: "json",
                data: {baidu: baidu},
                success: function (data) {
                    var vals = Number(data);
                    if (vals > 0) {
                        layer.msg("保存成功", {icon: 1});
                        //window.location.reload();
                    } else {
                        layer.msg("保存失败，请尝试刷新页面后操作", {icon: 2});
                    }
                }
            });
        }
        function scconfig() {
            var filesizetourists = $("#filesizetourists").val();
            var filesizeuser = $("#filesizeuser").val();
            var imgcounttourists = $("#imgcounttourists").val();
            var imgcountuser = $("#imgcountuser").val();
            var suffix = $("#suffix").val();
            var imgurltype = $('#imgurltype input[name="urltype"]:checked ').val();
            var visitormemory = $('#visitormemory').val();
            var usermemory = $('#usermemory').val();
            var re = new RegExp("^[0-9]*[1-9][0-9]*$");
            if(filesizetourists!=""&&filesizeuser!=""&&imgcounttourists!=""&&imgcountuser!=""&&suffix!=""&&visitormemory!=""&&usermemory!=""){
                if(re.test(filesizetourists) && re.test(imgcounttourists) && re.test(filesizeuser) && re.test(imgcountuser)){
                    $.ajax({
                        type: "POST",
                        url: "/admin/root/scconfig",
                        dataType: "json",
                        data: {filesizetourists: filesizetourists,filesizeuser:filesizeuser,imgcounttourists:imgcounttourists,
                            imgcountuser:imgcountuser,suffix:suffix,urltype:imgurltype,visitormemory:visitormemory,usermemory:usermemory},
                        success: function (data) {
                            var vals = Number(data);
                            if (vals > 0) {
                                layer.msg("保存成功", {icon: 1});
                                //window.location.reload();
                            } else {
                                layer.msg("保存失败，请尝试刷新页面后操作", {icon: 2});
                            }
                        }
                    });
                }else{
                    layer.msg("上传大小配置只可输入整数", {icon: 2});
                }
            }else{
                layer.msg("各项内容不能为空", {icon: 2});
            }
        }
        //设置游客是否上传
        function isupdate(values) {
            $.ajax({
                type: "POST",
                url: "/admin/root/scconfig",
                dataType: "text",
                data: {isupdate: values},
                success: function (data) {
                    var vals = Number(data);
                    if (vals > 0) {
                        if (values == 1) {
                            layer.msg("游客上传已开启", {icon: 1});
                        } else {
                            layer.msg("游客上传已禁用", {icon: 1});
                        }
                    } else {
                        layer.msg("操作失败，请重新打开页面会后尝试", {icon: 2});
                    }
                }
            });
        }
        //设置开启/关闭图床api
        function upapi(values) {
            $.ajax({
                type: "POST",
                url: "/admin/root/scconfig",
                dataType: "text",
                data: {api: values},
                success: function (data) {
                    var vals = Number(data);
                    if (vals > 0) {
                        if (values == 1) {
                            layer.msg("已开启站点API", {icon: 1});
                        } else {
                            layer.msg("已禁用站点API", {icon: 1});
                        }
                    } else {
                        layer.msg("操作失败，请重新打开页面会后尝试", {icon: 2});
                    }
                }
            });
        }

        function setstate(values) {
            $.ajax({
                type: "POST",
                url: "/admin/root/setstate",
                dataType: "json",
                data: {register: values},
                success: function (data) {
                    var vals = Number(data);
                    if (vals > 0) {
                        if (values == 1) {
                            layer.msg("已开放注册功能", {icon: 1});
                        } else {
                            layer.msg("已禁用注册功能", {icon: 1});
                        }
                    } else {
                        layer.msg("操作失败，请重新打开页面会后尝试", {icon: 2});
                    }
                }
            });
        }

        function webset() {
            $.ajax({
                type: "POST",
                url: "/admin/root/settstoragetype",
                dataType: "json",
                data: {storagetype: group},
                success: function (data) {
                    var vals = Number(data);
                    if (vals > 0) {
                        layer.msg("保存成功", {icon: 1});
                        //window.location.reload();
                    } else {
                        layer.msg("保存失败，请尝试刷新页面后操作", {icon: 2});
                    }
                }
            });
        }
    </script>
</body>
</html>